#ifndef SWEGL_SPHERE_H
#define SWEGL_SPHERE_H

namespace swegl
{

class Sphere
{
public:
	// default contructor, do not initialize components
	Sphere();
	Sphere(const Vec3 &center, float radius);

	Sphere &set(const Vec3 &center, float radius);
	Sphere(const Sphere &rhs);
	Sphere &operator = (const Sphere &rhs);

	bool operator == (const Sphere &rhs) const;
	bool operator != (const Sphere &rhs) const;
	
	void setCenter(const Vec3 &center);
	const Vec3 &center() const;
	Vec3 &center();
	
	void setRadius(float radius);
	float radius() const;
	
	//bool intersects(const Sphere &s) const;
	//bool intersects(const AxisAlignedBox &box) const
	//bool intersects(const Plane &plane) const
	bool contains(const Vec3 &p) const;
	
	const float *toFloatPtr() const;
	float *toFloatPtr();
	
private:
	Vec3 m_center;
	float m_radius;
};

inline Sphere::Sphere()
{
}

inline Sphere::Sphere(const Vec3 &center, float radius) : m_center(center), m_radius(radius)
{
}

inline Sphere &Sphere::set(const Vec3 &center, float radius)
{
	m_center = center;
	m_radius = radius;
	return *this;
}

inline Sphere::Sphere(const Sphere &rhs) : m_center(rhs.m_center), m_radius(rhs.m_radius)
{
}

inline Sphere &Sphere::operator = (const Sphere &rhs)
{
	m_center = rhs.m_center;
	m_radius = rhs.m_radius;
	return *this;
}

inline bool Sphere::operator == (const Sphere &rhs) const
{
	return m_center == rhs.m_center && m_radius == rhs.m_radius;
}

inline bool Sphere::operator != (const Sphere &rhs) const
{
	return m_center != rhs.m_center || m_radius != rhs.m_radius;
}

inline void Sphere::setCenter(const Vec3 &center)
{
	m_center = center;
}

inline const Vec3 &Sphere::center() const
{
	return m_center;
}

inline Vec3 &Sphere::center()
{
	return m_center;
}

inline void Sphere::setRadius(float radius)
{
	m_radius = radius;
}

inline float Sphere::radius() const
{
	return m_radius;
}

inline bool Sphere::contains(const Vec3 &p) const
{
	return (m_center - p).sqrLength() <= m_radius * m_radius;
}

inline const float *Sphere::toFloatPtr() const
{
	return m_center.toPtr();
}

inline float *Sphere::toFloatPtr()
{
	return m_center.toPtr();
}

}

#endif
